﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;

namespace CPPEI.PM.Service.Model.Repository
{
    public class WorkItemRefRepository
    {
        private DbContext _dbContext;
        public WorkItemRefRepository(DbContext dbContext)
        {
            _dbContext = dbContext;
        }

        public void Create(WorkItemRef workItemRef)
        {
            _dbContext.Set<WorkItemRef>().Add(workItemRef);
        }

        public WorkItemRef Get(Guid workSheetId, Guid workItemId)
        {
            return _dbContext.Set<WorkItemRef>().SingleOrDefault(p => p.WorkSheetId == workSheetId && p.WorkItemId == workItemId);
        }

        public List<WorkItemRef> GetByParent(Guid workSheetId, Guid workItemCategoryId, Guid parentWorkItemId)
        {
            return _dbContext.Set<WorkItemRef>().Where(p => p.WorkSheetId == workSheetId && p.WorkItemCategoryId == workItemCategoryId && p.ParentWorkItemId == parentWorkItemId).ToList();
        }
    }
}
